package main

import (
	"fmt"
	"sync"
)

var (
	instance *Singleton
	mu       sync.Mutex
)

type Singleton struct {
}

func GetInstance() *Singleton {
	if instance == nil {
		mu.Lock()
		defer mu.Unlock()
		if instance == nil {
			instance = &Singleton{}
		}
	}
	return instance
}

// 双重检测锁实现单例模式
func main() {
	singleton := GetInstance()
	fmt.Println(singleton)
}
